package at.ac.tuwien.sepm.s2011.e0208329.services;

import java.sql.SQLException;

import at.ac.tuwien.sepm.s2011.e0208329.dao.DAOFactoryImpl;
import at.ac.tuwien.sepm.s2011.e0208329.dao.DienstleistungDAOImpl;
import at.ac.tuwien.sepm.s2011.e0208329.dao.OrderDAOImpl;

/**
 * this class should provide the functions for making orders, which means:
 * save the orders as entries in DB's table "RechnungItem"
 * and make change of the "VerkaufsZahl" on ordered Services
 */
public class MyOrderServiceImpl implements MyOrderService{
	private OrderDAOImpl orderDAO;
	private DienstleistungDAOImpl serviceDAO;
	public static MyOrderServiceImpl refOrderService;
	
	public MyOrderServiceImpl() {
		super();
		orderDAO = DAOFactoryImpl.getDAOFactory().getOrderDAO();
		serviceDAO = DAOFactoryImpl.getDAOFactory().getServiceDAO();
	}

	@Override
	public void order(int billID, int serviceID, int number) throws SQLException { // call method from OrderDAO to insert an entry
		orderDAO.storeSingleOrderItem(billID, serviceID, number);
		
	}
	
	public static MyOrderServiceImpl getInstance() { // getter
	    if(refOrderService == null){
	    	refOrderService = new MyOrderServiceImpl();
	    }
	    return refOrderService;
	}
	
	public void updateSalesNo(int serviceID, int sale) throws SQLException{ // call method from OrderDAO to update a "VerkaufsZahl"
		serviceDAO.setSaleNumber(serviceID,sale);
		
	}

}
